package com.ruoyi.common.utils;

import com.ruoyi.common.core.domain.entity.SysDept;

import java.util.List;

public class SysDeptUtil {
    /**
     * 根据部门名称和层级查找部门
     */
    public static SysDept findDeptById(String deptName, int level, SysDept parent, List<SysDept> deptList) {
        if (StringUtils.isEmpty(deptName) || parent == null) {
            return null;
        }
        return deptList.stream()
                .filter(x -> x.getDeptName().equals(deptName) &&
                        x.getAncestors().contains(parent.getDeptId().toString()) &&
                        x.getLevel() == level)
                .findFirst()
                .orElse(null);
    }
}
